/**
 * Anderground project - Subway maps processor application.
 * Copyright (C) 2008-2009 Eldar Abusalimov, Ilya Shurigyn
 * 
 * This file is part of Anderground.
 * 
 * Anderground is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * Anderground is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Anderground.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.anderground.modules.drawer.dynamic;

import static org.anderground.modules.drawer.dynamic.Config.fontSize;

import java.util.ArrayList;
import java.util.HashMap;

import org.anderground.core.drawer.Calculator;
import org.anderground.core.graphics.Canvas;
import org.anderground.core.graphics.Color;
import org.anderground.core.graphics.Paint;
import org.anderground.core.graphics.PointF;
import org.anderground.core.model.Station;
import org.anderground.core.util.Point;
import org.anderground.internal.graphics.abstaractions.AbstractPaint.Style;

/**
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 * 
 */
abstract class Amoeba {

	protected Crossing crossing;

	protected CompoundAmoeba parentAmoeba;

	protected Amoeba brotherAmoeba;

	private HashMap<Amoeba, Bacillus> bacillusMap = new HashMap<Amoeba, Bacillus>();

	public Bacillus getBacillus(Amoeba amoeba) {
		return bacillusMap.get(amoeba);
	}

	void addNeighbor(Amoeba neighborAmoeba, Bacillus bacillus) {
		bacillusMap.put(neighborAmoeba, bacillus);
	}

	protected PointF coordF;

	protected int[] colors;

	protected PointF[] coords;

	protected Station[] stations;

	protected int size;

	protected PointF pointF = new PointF();

	protected static Paint simplePaint = new Paint();

	protected static Paint complexPaint = new Paint();

	protected static Paint backSimplePaint = new Paint();

	protected static Paint backComplexPaint = new Paint();

	protected static Paint lightSimplePaint = new Paint();

	protected static Paint lightComplexPaint = new Paint();

	protected static Paint labelPaint = new Paint();

	protected abstract void applyCalculator(Calculator calculator);

	protected abstract void addDrawnAmoebas(ArrayList<Amoeba> drawnAmoebas);

	protected abstract void draw(Canvas canvas);

	protected abstract void highlight(Canvas canvas, int highlightColor);

	protected void drawLabels(Canvas canvas) {
		if (!Config.drawLabels) {
			return;
		}
		for (int i = 0; i < stations.length; i++) {
			Station station = stations[i];
			Point offset = station.getLabel().getOffset();
			if (station.getLabel().isVisible()) {
				canvas.drawText(station.getName(), pointF.x + offset.getX(),
						pointF.y + offset.getY(), labelPaint);
			}
		}
	}

	public static void setup() {
		labelPaint.setTextSize(fontSize);
	}

	static {

		complexPaint.setAntiAlias(true);
		complexPaint.setStrokeCap(Paint.Cap.BUTT);
		complexPaint.setStyle(Style.FILL_AND_STROKE);

		simplePaint.setAntiAlias(true);
		simplePaint.setStrokeCap(Paint.Cap.ROUND);

		backComplexPaint.setAntiAlias(true);
		backComplexPaint.setStrokeCap(Paint.Cap.ROUND);
		backComplexPaint.setColor(Color.LTGRAY);

		backSimplePaint.setAntiAlias(true);
		backSimplePaint.setStrokeCap(Paint.Cap.ROUND);
		backSimplePaint.setColor(Color.LTGRAY);

		lightComplexPaint.setAntiAlias(true);
		lightComplexPaint.setStrokeCap(Paint.Cap.ROUND);

		lightSimplePaint.setAntiAlias(true);
		lightSimplePaint.setStrokeCap(Paint.Cap.ROUND);

		labelPaint.setAntiAlias(true);
		labelPaint.setColor(Color.DKGRAY);

	}

}
